package com.mystnihon.actions;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport implements SessionAware {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String MLOGIN = "kowlown";
	private static final String MPASSWORD = "maggot971";

	private String login;
	private String password;

	private Map<String, Object> session;

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	
	public String authentifier(){

		if(this.login!=null && this.password!=null) 
			if ((this.login.equals(LoginAction.MLOGIN)) && (this.password.equals(LoginAction.MPASSWORD))) {

				this.session=getSession();
				this.session.put("allowAccess", "true");
				return "success";
			}
		
		addFieldError("login", getText("developpez.message.authent echouee"));
		return "input";
	}

	public String deconnecter (){
		System.out.println("dans la méthode deconnecter.......");
		this.session.clear();
		return "success";

	}

	@Override
	public void setSession(Map<String, Object> obj) {
		this.session = obj;
	}

	public Map<String, Object> getSession() {

		return session;

	}

}
